package com.gwtgeo.service.dao.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.postgis.PGgeometry;
import org.postgis.Point;
import org.springframework.jdbc.core.RowMapper;

import com.gwtgeo.service.model.Location;

public class LocationRowMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		Location location = new Location();
		location.setId(rs.getLong("id"));
		location.setName(rs.getString("name"));
		PGgeometry geom = (PGgeometry) rs.getObject("geom");
		Point point = (Point) geom.getGeometry(); 
		location.setLatitude(point.getY());
		location.setLongitude(point.getX());
		return location;
	}

}
